package imvu.rbox.object
{
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;

	public class TimeObject extends Sprite
	{
		public var txtTime:TextField;		//	计时器对象
		
		private var lastTime:Number;		//	剩余时间（以秒为单位计时）
		private var gTime:Timer;
		
		public function TimeObject()
		{
			this.time = 0;
		}	
		
		public function StartTime():void
		{
			this.lastTime = 0;
			

			gTime = new Timer(1000);
			gTime.addEventListener(TimerEvent.TIMER, onCheckTime);			
			gTime.start();	
		}
		
		public function StopTime():void
		{
			this.time = 0;
			if(gTime)
			{
				gTime.stop();
				gTime.removeEventListener(TimerEvent.TIMER, onCheckTime);
				gTime = null;
			}
		}
		
		private function onCheckTime(e:TimerEvent):void
		{
			this.lastTime ++;
			this.time = this.lastTime;
		}
		
		//	设置当前的剩余时间
		public function set time(num:Number):void
		{
			var sec:Number = num % 60;
			var min:Number = Math.floor(num / 60);
			
			lastTime = num;
			
			this.txtTime.text = String("00" + min).substr(-2) + ":" + String("00" + sec).substr(-2);
		}
		
		//	取得当前的剩余时间
		public function get time():Number
		{
			return this.lastTime;
		}
	}
}